package com.gm;

import java.io.PrintWriter;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Scanner;

/**
 * Created by Administrator on 13-12-23.
 */
public class Employee {

    private String name;
    private double salary;
    private Date hireDate;

    public Employee()
    {

    }
    public Employee(String name, double salary,int year,int month,int day) {
        this.name = name;
        this.salary = salary;

        GregorianCalendar calendar=new GregorianCalendar(year,month-1,day);
        this.hireDate=calendar.getTime();
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public Date getHireDate() {
        return hireDate;
    }

    @Override
    public String toString() {
        return "Employee{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                ", hireDate=" + hireDate +
                '}';
    }

    public void writeData(PrintWriter writer){
        GregorianCalendar calendar=new GregorianCalendar();
        calendar.setTime(this.hireDate);

        writer.println(name + "|" + this.salary + "|"
                + calendar.get(Calendar.YEAR) + "|"
                + (calendar.get(Calendar.MONTH)+1) + "|"
                + calendar.get(Calendar.DAY_OF_MONTH));
    }

    public void readData(Scanner in){
        String line=in.nextLine();

        String[] tokens=line.split("\\|");
        name=tokens[0];
        salary=Double.parseDouble(tokens[1]);
        int year=Integer.parseInt(tokens[2]);
        int month=Integer.parseInt(tokens[3]);
        int day=Integer.parseInt(tokens[4]);

        GregorianCalendar calendar=new GregorianCalendar(year,month-1,day);
        hireDate=calendar.getTime();
    }
}
